//时间戳转换成日期时间(年月日)
function js_date_time(unixtime) {
	// console.log(unixtime);
	var dateTime = new Date(parseInt(unixtime) * 1000)
	var year = dateTime.getFullYear();
	var month = dateTime.getMonth() + 1;
	if (month > 0 && month < 10) {
		month = "0" + month;
	}
	var day = dateTime.getDate();
	if (day > 0 && day < 10) {
		day = "0" + day;
	}
	var hour = dateTime.getHours();
	var minute = dateTime.getMinutes();
	var second = dateTime.getSeconds();
	var now = new Date();
	var now_new = Date.parse(now.toDateString()); //typescript转换写法
	var milliseconds = now_new - dateTime;
	var timeSpanStr = year + '-' + month + '-' + day;
	// console.log(timeSpanStr);
	return timeSpanStr;
}

//时间戳转换成日期时间(年月日时分秒)
function js_date_time_second(time) {
	var date = new Date(time * 1000);
	var y = date.getFullYear();
	var m = date.getMonth() + 1;
	m = m < 10 ? ('0' + m) : m;
	var d = date.getDate();
	d = d < 10 ? ('0' + d) : d;
	var h = date.getHours();
	h = h < 10 ? ('0' + h) : h;
	var minute = date.getMinutes();
	var second = date.getSeconds();
	minute = minute < 10 ? ('0' + minute) : minute;
	second = second < 10 ? ('0' + second) : second;
	var timeStr = y + '-' + m + '-' + d + '　' + h + ':' + minute + ':' + second;
	return timeStr;
}

//随机抽取3/10的数据
function thirtyPercent(len){
	let arr = [];
	for(let i =0;i<len;i++){
		arr.push(i);
	}
	arr.sort(function(a, b){
		return Math.random() > 0.5 ? -1 : 1;
	})
	let arr2 = arr.slice(0, Math.floor(len/3));
	arr2.sort(function(a, b){
		return a-b;
	})
	return arr2;
}

//随机处理k线数据
function randomData(arr){
	let indexList = thirtyPercent(arr.length);
	let newArr = [];
	for(let i = 0; i< arr.length; i++){
		if(indexList.indexOf(i)!=-1){
			newArr.push(arr[i]);
		}
	}
	return newArr;
}


// export { js_date_time, js_date_time_second, randomData }